#include "renderForce.h"
#define SCALE 4
#define HEIGHT 4

renderForce::renderForce(float init_red, float init_green, float init_blue)
{
	// Initialize the variables then load the texture!
	r = init_red; g = init_green; b = init_blue;
	loadOpenGL2DTextureBMP("arrow.bmp", &floor_texture, GL_RGB);
}

renderForce::~renderForce(void)
{
}

// This draw method is intended to draw the shapes, set the material
// and appropriately texture the shapes generated.
void renderForce::draw(float init_x, float init_y, float init_z, Direction dir)
{

	x = (init_x * SCALE);
	y = (init_y * SCALE);
	z = (init_z * SCALE);

	GLfloat mat_ambient[] = { 0.2, 0.2, 0.2, 1};
	GLfloat mat_diffuse[] = { 0.2, 0.2, 0.2, 1 };
	GLfloat mat_specular[] = { 0.2, 0.2, 0.2, 1 };

	glPushMatrix();

	//	/* Set up material properties. */
	glEnable(GL_TEXTURE_2D);
	glTranslatef(x, y, z);
	glColor3f(1, 1,1); 

	glBindTexture(GL_TEXTURE_2D, floor_texture); 	
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialf(GL_FRONT, GL_SHININESS, 100.0 ); /* No effect if specular == 0 */

	// This method has an additional Direction component which used here
	// will rotate the rendering of the floor panel appropriately.
	int newDir = 0;
	switch (dir){
	case UP:
		newDir = 2;		
		glTranslatef(SCALE,SCALE,0);
		glRotatef(newDir * 90, 0.0, 0.0, 1.0);
		//glTranslatef(-SCALE,-SCALE,0);
		break;
	case DOWN:
		newDir = 0;
		glTranslatef(SCALE,SCALE,0);
		glRotatef(newDir * 90, 0.0, 0.0, 1.0);
		glTranslatef(-SCALE,-SCALE,0);
		break;
	case RIGHT:
		newDir = 1;
		glTranslatef(0,SCALE,0);
		glRotatef(newDir * 90, 0.0, 0.0, 1.0);
		glTranslatef(-SCALE,-SCALE,0);
		break;
	case LEFT:
		newDir = 3;
		glTranslatef(0,SCALE,0);
		glRotatef(newDir * 90, 0.0, 0.0, 1.0);
		//glTranslatef(-SCALE,-SCALE,0);
		break;	
	}

	glColor3f(r,g,b);

	//First section
	glScalef(1.0, 1.0, 0.2);
	//START THE QUADS!
	glBegin(GL_QUADS);


	glNormal3f(0,0,-1);
	glNormal3f(0,0,1);			
	glNormal3f(-1,0,0);
	glNormal3f(1,0,0);
	glNormal3f(0,-1,0);
	glNormal3f(0,1,0);

	glNormal3f(0,0,-1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, 0.0);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, 0.0);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, 0.0);

	glNormal3f(0,0,1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, SCALE);


	glNormal3f(-1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);


	glNormal3f(1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);

	glNormal3f(0,-1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, 0.0, 0.0);

	glNormal3f(0,1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

	glEnd();

	glScalef(1.0, 1.0, 1/0.2);

	glTranslatef(-x, -y, -z );
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();

	glFlush();

}